package com.openitems.data.management;

import org.hibernate.SessionFactory;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;

public enum SessionManagement {
	INSTANCE;
	private SessionFactory sessionFactory;
	
	private SessionManagement(){
		 Configuration configuration = new Configuration();
	     configuration.configure("/resources/hibernate.cfg.xml");

	     StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder();
	     serviceRegistryBuilder.applySettings(configuration.getProperties());
	     ServiceRegistry serviceRegistry = serviceRegistryBuilder.build();

	     sessionFactory = configuration.buildSessionFactory(serviceRegistry);
	     
	}
	
	public SessionFactory getSessionFactory(){
		return sessionFactory;
	}

}
